package com.example.trader.service;


import com.example.trader.common.Result;
import com.example.trader.entity.Product;
import com.example.trader.mapper.ProductManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductManagerService {


    @Autowired
    private ProductManagerMapper productManagerMapper;
    public List<Product> getProductList() {
       List<Product> productList= productManagerMapper.getProductList();
       return productList;
    }

    public Result addProduct(Product product) {
        int result = productManagerMapper.addProduct(product);
        if (result==0){
            return Result.error("400","添加失败");
        }
        return Result.success("新增成功");
    }

    public Result deleteProduct(Integer id) {

        int result = productManagerMapper.deleteProduct(id);
        if(result==0){
            return Result.error("400","删除失败");
        }
        return Result.success("删除成功");
    }

    public Result editProductInfo(Product product) {

        int result = productManagerMapper.editProductInfo(product);
        if(result==0){
            return Result.error("400","编辑失败");
        }
        return Result.success("编辑成功");
    }

    public List<Product> getProductByName(String productName) {
        List<Product> productList=productManagerMapper.getProductByName(productName);
        return productList;
    }


}
